<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2020/7/22
  Time: 20:00
  To change this template use File | Settings | File Templates.
--%>
<%--
  Created by IntelliJ IDEA.
  User: 10218
  Date: 2019/06/30
  Time: 11:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.demo.packageModel.Together" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.Iterator" %>

<script src="${ctx}/webjars/jquery/3.3.1-2/jquery.min.js"></script>
<html>
<head>
    <title>sql-insert</title>
</head>

<body>


<button onclick="SQLscan()">确定插入</button><br>
<button onclick="scanback()">返回</button><br>


empno:<input type="text" name="firstname" id="empno" value=""><br>
ename:<input type="text" name="firstnumb" id="empname" value=""><br>
job:<input type="text" name="firstname" id="empjob" value=""><br>
mgr:<input type="text" name="firstnumb" id="empmgr" value="NULL"><br>
hiredate:<input type="text" name="firstname" id="emphiredate" value="2020-07-29"><br>
sal:<input type="text" name="firstnumb" id="empsal" value=""><br>
comm:<input type="text" name="firstname" id="empcomm" value="NULL"><br>
deptno:<input type="text" name="firstnumb" id="empdepyno" value=""><br>
<script>
    //输入数据
    function SQLscan() {
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        xmlhttp.open("POST", "/test/scanf", false);


        var text0=document.getElementById("empno");
        var text1=document.getElementById("empname");
        var text2=document.getElementById("empjob");
        var text3=document.getElementById("empmgr");
        var text4=document.getElementById("emphiredate");
        var text5=document.getElementById("empsal");
        var text6=document.getElementById("empcomm");
        var text7=document.getElementById("empdepyno");

        if(text0.value == "") {
            alert("empno is empty!!!");
            return false;
        }
        if(text1.value == "") {
            alert("empname is empty!!!");
            return false;
        }
        if(text2.value == "") {
            alert("job is empty!!!");
            return false;
        }

        if(text4.value == "") {
            alert("hiredate is empty!!!");
            return false;
        }
        if(text5.value == "") {
            alert("sal is empty!!!");
            return false;
        }

        if(text7.value == "") {
            alert("deptno is empty!!!");
            return false;
        }

        var person = {
            empno : text0.value,
            name: text1.value,
            job : text2.value,
            mgr: text3.value,
            hiredate : text4.value,
            sal: text5.value,
            comm : text6.value,
            deptno: text7.value,
        };
        var json = JSON.stringify(person);
        //alert(json);
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlhttp.send(json);

        xmlhttp.open("GET", "/test/insertflag", true);
        xmlhttp.send();
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;
                alert(t);
            }
        };
    }

    //跳回主界面
    function scanback() {
        window.location.href = "http://localhost:8080/test/6";
    }

</script>
</body>
</html>
